﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Saker.Kernel.BLL;
using Saker.Kernel.Model;
using System.Data;

namespace Saker.Web.Boss.Sys.Role
{
    public partial class RoleAuthority : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        public void BindData()
        {
            RepModulesList.DataSource = new SysModuleBLL().GetAll();
            RepModulesList.DataBind();
        }

        protected void RepModulesList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }

        protected void RepModulesList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            CheckBoxList cbList = (CheckBoxList)e.Item.FindControl("cbAuthority");
            Label lab_ID = (Label)e.Item.FindControl("lab_ID");
            
            DataTable dt = new SysModuleAuthorityListBLL().GetModuleAuthorityList();
            DataRow[] rows = dt.Select("ModuleID='" + lab_ID.Text + "'");
            foreach (DataRow row in rows)
            {
                ListItem item = new ListItem(row["AuthorityName"].ToString(), row["AuthorityTag"].ToString());
                cbList.Items.Add(item);
                cbList.RepeatColumns = rows.Length;
            }
        }
    }
}